package cn.hexcloud.dga.meta.mapper;

import cn.hexcloud.dga.meta.bean.TableMetaInfo;
import cn.hexcloud.dga.meta.bean.TableMetaInfoVO;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 元数据表 Mapper 接口
 * </p>
 *
 * @author jiangdan7
 * @since 2023-08-23
 */
@Mapper
@DS("dga")
public interface TableMetaInfoMapper extends BaseMapper<TableMetaInfo> {

    @Select("${sql}")
    List<TableMetaInfoVO> selectTableMetaListPage(@Param("sql") String sql);

    @Select("${sql}")
    Integer selectTableMetaCount(@Param("sql") String sql);

    @Select("select t1.*,t2.*,t2.id te_id,t2.create_time te_create_time,t2.update_time te_update_time from table_meta_info t1 join table_meta_info_extra t2 on t1.table_name = t2.table_name and t1.schema_name = t2.schema_name where t1.assess_date = (select max(assess_date) from table_meta_info t3 where t1.table_name = t2.table_name and t1.schema_name = t2.schema_name)")
    @ResultMap("tableMetaInfoMap")
    List<TableMetaInfo> getTableMetaInfoListLastDt();
}
